package com.searshc.hadoop.migration;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CapturingGroupDemo {
    public static void main(String[] args) {
        //
        // Define regex to find the word 'the' or 'quick'
        //
//        String regex = "(.+)\\-eq(\\s+)(?=[^0])(?=[^1])(?=[^\\-1])";
        String regex = "hadoop(\\s+)(fs|dfs)(\\s+)\\-cat(\\s+)(?!\\b/(.+)\\b)";        
//        String text = "C = ( filter B by $0 > 0 ) as (RANK:bytearray, DATETIME:long); ";
//        String text = "C = JOIN big BY b1, massive BY m1 USING \"skewed\"";
//        String text = "C = JOIN big BY b1, massive BY m1 USING \"merge\"";
//        String text = "C = JOIN big BY b1, massive BY m1 USING \"replicated\"";
//        String text = "B =(customer);";
//        String text = "C = ( filter B by $0 > 0 ) as (a:bytearray, b:long);";
//        String text = "D = group A by $0 as b:LONG;";
//        String text = "C = filter B by $0 > 0 PARALLEL 10;";
//        String text = "X = FOREACH C GENERATE FLATTEN(B) ;";
//        String text = "store B into \"output\";";
//        String text = "B = STREAM A THROUGH `stream.pl -m 5 -e 6 -o 9 -m 10`";
//        String text = "a = load '1.bin' using BinStorage as (a0, a1, a2);";
//        String text = "stream IP through 'script' ship('/a/b/script') ship('/a/b/script');";
//        String text = "DEFINE CMD `perDEFINE CMD `perl PigStreaming.pl - nameMap` input(stdin using PigStreaming(',')) output(stdout using PigStreaming(',')) input(stdin using PigStreaming(','));";
//        String text = "X = FOREACH A GENERATE f2, (f2==1?1:COUNT(*));";
//        String text ="X = FOREACH A GENERATE SIZE(*);";
//        String text = "import org.apache.pig.impl.logicalLayer.parser.ParseException;";
//        String text = "hadoop fs -lsr /user/hadoop/file1";
//        String text = "hadoop fs -dus hdfs://namenodehost/user/hadoop";
//        String text = "if [ $? -eq 143 ] ";
//        String text = "B = GROUP A BY $0 USING \"collected\";";
      String text = "hadoop fs -cat /user/hadoop/file1";



        //
        // Compiles the given regular expression into a pattern and
        // Creates a matcher that will match the given input against
        // this pattern.
        //
        Pattern pattern = Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(text);

        //
        // Find every match and print it
        //
        while (matcher.find()) {        	
        	for(int i=0; i <= matcher.groupCount();i++){
	            System.out.format("Text \"%s\" found at %d to %d.%n, group no %d",
	                    matcher.group(i), matcher.start(), matcher.end(), i+1); 
        	}
        }
    }
}
